www.gusucode.com > VC 2D游戏编辑器-源码程序 > VC 2D游戏编辑器-源码程序/code/game_Source/GameLib/map/map.cpp
//Download by http://www.NewXing.com #include "map.h" #include "..\\globle_func.h" #include "..\\globle.h" #include "..\\..\\newgame.h" CMap::CMap(long ID, char *cName, char *szMapFile) { pSurfaceData = NULL; pObjLink = NULL; lCellNumber = NULL; LoadMap(ID, cName, szMapFile); } CMap::CMap( ) { pSurfaceData = NULL; pObjLink = NULL; lCellNumber = NULL; cMapName[0] = '\0'; } CMap::~CMap( ) { PA_SAFE_DELETE(pSurfaceData); if(pObjLink) { _ObjLink* pLink; while(pObjLink) { pLink = pObjLink->Next; delete pObjLink; pObjLink = pLink; } pObjLink = NULL; pLink = NULL; } cMapName[0] = '\0'; } void CMap::LoadMap(long ID, char *cName, char *szMapFile) { if((cName[0] == '\0')||(cName[0] == 0)) return; PA_SAFE_DELETE(pSurfaceData); if(pObjLink) { _ObjLink* pLink; while(pObjLink) { pLink = pObjLink->Next; delete pObjLink; pObjLink = pLink; } pObjLink = NULL; pLink = NULL; } FILE *file=fopen(szMapFile,"rb"); if(!file) { MsgBox("不能打开地图文件!%s",szMapFile); return; } fread(&pHeader, sizeof(_MapHeader),1,file); long lWidth = pHeader.nWidth; long lHeight = pHeader.nHeight; _ObjCell* pObjData; pSurfaceData=new _SurfaceCell[lWidth*lHeight]; pObjData = new _ObjCell[lWidth*lHeight]; fread((char *)pSurfaceData, lWidth*lHeight*sizeof(_SurfaceCell), 1, file); fread((char *)pObjData, lWidth*lHeight*sizeof(_ObjCell), 1, file); fread((char *)&lCellNumber, sizeof(long), 1, file); _ObjLink* pLink = NULL; _ObjLink* pLink1 = NULL; pObjLink = NULL; while(lCellNumber != 0) { pLink = new _ObjLink; fread(pLink, 2*sizeof(DWORD), 1, file); if(pObjData[pLink->dy*lWidth+pLink->dx].nID == 255) pObjData[pLink->dy*lWidth+pLink->dx].nID = 0; pLink->ObjCell.nID = pObjData[pLink->dy*lWidth+pLink->dx].nID; pLink->ObjCell.nRealY = pObjData[pLink->dy*lWidth+pLink->dx].nRealY; if((pObjData[pLink->dy*lWidth+pLink->dx].nType < 1)||(pObjData[pLink->dy*lWidth+pLink->dx].nType > 7)) pObjData[pLink->dy*lWidth+pLink->dx].nType = 1; pLink->ObjCell.nType = pObjData[pLink->dy*lWidth+pLink->dx].nType-1; pLink->ObjCell.res = pObjData[pLink->dy*lWidth+pLink->dx].res; if(pObjLink == NULL) { pObjLink = pLink; pLink1 = pLink; pLink1->Next = NULL; pLink = NULL; } else { pLink1->Next = pLink; pLink1 = pLink1->Next; pLink1->Next = NULL; pLink = NULL; } lCellNumber --; } delete[] pObjData; fclose(file); iMapID = ID; strcpy(cMapName, cName); } void CMap::ShowMap_Surface(RECT rect, long dx, long dy) { if(rect.left < 0) rect.left = 0; if(rect.top < 0) rect.top = 0; if(rect.right > pHeader.nWidth << 5) rect.right = pHeader.nWidth << 5; if(rect.bottom > pHeader.nHeight << 5) rect.bottom = pHeader.nHeight << 5; if(dx + (rect.right - rect.left) > SW[SMap]) { rect.right = rect.left + SW[SMap] - dx; } if(dy + rect.bottom - rect.top > SH[SMap]) { rect.bottom = rect.top + SH[SMap] - dy; } rect.left = rect.left >> 5; rect.right = rect.right >> 5; rect.top = rect.top >> 5; rect.bottom = rect.bottom >> 5; DrawDynamicPic(rect, dx, dy); if((rect.left == rMapRect.left)&&(rect.right == rMapRect.right)&&(rect.top == rMapRect.top)&&(rect.bottom == rMapRect.bottom)) { return; } int iStartX, iStartY; // if(bFirstDrawMap == true) // { iStartX = rect.left - 10 > 0? -10: 0; iStartY = rect.top - 10 > 0? -10: 0; DrawMapNoTran(iStartX, iStartY, rect, dx, dy); //绘制无过渡图形 iStartX = rect.left - 1 > 0? -1: 0; iStartY = rect.top - 1 > 0? -1: 0; RECT rect1; rect1.left = rect.left; rect1.top = rect.top; rect1.right = rect.right + 1 < pHeader.nWidth? rect.right + 1 : rect.right; rect1.bottom = rect.bottom + 1 < pHeader.nHeight? rect.bottom + 1 : rect.bottom; rect1.right = (dx + rect1.right - rect.left) < (SW[SMap] >>5)? rect1.right : rect.right; rect1.bottom = (dy + rect1.bottom - rect.top) < (SH[SMap] >>5)? rect1.bottom : rect.bottom; DrawMapTran(iStartX, iStartY, rect1, dx, dy); //绘制过渡图形 bFirstDrawMap = false; // } /* else { if(rect.left <= rMapRect.left) { if(rect.top <= rMapRect.top) { MoveMapRD(rect, dx, dy); //将地图向右下角移 } else { MoveMapRU(rect, dx, dy); //将地图向右上角移 } } else { if(rect.top <= rMapRect.top) { MoveMapLD(rect, dx, dy); //将地图向左下角移 } else { MoveMapLU(rect, dx, dy); //将地图向左上角移 } } } */ rMapRect.left = rect.left; rMapRect.right = rect.right; rMapRect.top = rect.top; rMapRect.bottom = rect.bottom; } void CMap::ShowMap_Obj(RECT rect, long dx, long dy) { _ObjLink* pLink; _ZoeticLink * pLink1; pLink = pObjLink; pLink1 = Zoetic->ZoeticLinkHeader; int iObjX, iObjY; RECT rect1; bool IsShowRole = false; while((pLink != NULL)||(pLink1 != NULL)) { if((pLink != NULL)&&((pLink1 == NULL)||((pLink->ObjCell.nRealY<<10)+pLink->dx < ((pLink1->dCurrent_y>>5)<<10)+pLink1->dCurrent_x))) { if((pLink->ObjCell.nType > 6)||(pLink->ObjCell.nID == 255)) { pLink = pLink->Next; continue; } rect1.right = pObjCell[pLink->ObjCell.nType][pLink->ObjCell.nID].pRleBitHeader->bfWidth; rect1.bottom = pObjCell[pLink->ObjCell.nType][pLink->ObjCell.nID].pRleBitHeader->bfHeight; iObjX = pLink->dx << 5; iObjY = pLink->dy << 5; if((iObjX + rect1.right >= rect.left)&&(iObjY +rect1.bottom >= rect.top)&&(iObjX < rect.right)&&(iObjY < rect.bottom)) { if(iObjX < rect.left) rect1.left = rect.left - iObjX; else rect1.left = 0; if(iObjY < rect.top) rect1.top = rect.bottom - iObjY; else rect1.top = 0; if(rect1.right + iObjX > rect.right) rect1.right = rect.right - iObjX; if(rect1.bottom + iObjY > rect.bottom) rect1.bottom = rect.bottom - iObjY; if(IsShowRole) ShowRleImage(iObjX < rect.left?0:iObjX-rect.left+dx, iObjY < rect.top?0:iObjY-rect.top+dy, 0 ,0 , rect1, pObjCell[pLink->ObjCell.nType][pLink->ObjCell.nID].pRleBitHeader, pS[SBuffer], SP[SBuffer]); else if((long)((pLink->ObjCell.nRealY<<10)+pLink->dx) < (long)(((role->y>>5)<<10)+(role->x>>5))) { ShowRleImage(iObjX < rect.left?0:iObjX-rect.left+dx, iObjY < rect.top?0:iObjY-rect.top+dy, 0 ,0 , rect1, pObjCell[pLink->ObjCell.nType][pLink->ObjCell.nID].pRleBitHeader, pS[SBuffer], SP[SBuffer]); } else { role->show( ); IsShowRole = true; ShowRleImage(iObjX < rect.left?0:iObjX-rect.left+dx, iObjY < rect.top?0:iObjY-rect.top+dy, 0 ,0 , rect1, pObjCell[pLink->ObjCell.nType][pLink->ObjCell.nID].pRleBitHeader, pS[SBuffer], SP[SBuffer]); } } pLink = pLink->Next; } else { if(IsShowRole) Zoetic->ShowZoeticI(pLink1->dI); else if((long)((pLink1->dCurrent_y<<5)+pLink1->dCurrent_x) < (long)((role->y<<5)+(role->x>>5))) { Zoetic->ShowZoeticI(pLink1->dI); } else { role->show( ); IsShowRole = true; Zoetic->ShowZoeticI(pLink1->dI); } pLink1 = pLink1->Next; } } if(!IsShowRole) role->show( ); } void CMap::DrawMapNoTran(int iStartX, int iStartY, RECT rect, long dx, long dy) { int x, y, number; int iSurfaceX, iSurfaceY; RECT rect1; for(y = iStartY; y < rect.bottom-rect.top; y++) for(x = iStartX; x < rect.right-rect.left; x++) { number = (rect.top+y) * pHeader.nWidth + rect.left + x; if((!pSurfaceData[number].nUseTranSition)&&(pSurfaceData[number].nID < 21)) { rect1.right = pSourCell[pSurfaceData[number].nID].pBmpHeader->bfWidth; rect1.bottom = pSourCell[pSurfaceData[number].nID].pBmpHeader->bfHeight; iSurfaceX = (x + rect.left) << 5; iSurfaceY = (y + rect.top) << 5; if((iSurfaceX < rect.right << 5)&&(iSurfaceX + rect1.right > rect.left << 5)&&(iSurfaceY < rect.bottom << 5)&&(iSurfaceY + rect1.bottom > rect.top << 5)) { if(x < 0) rect1.left = (0 - x)<<5; else rect1.left = 0; if(y < 0) rect1.top = (0 - y)<<5; else rect1.top = 0; if(iSurfaceX + rect1.right > rect.right << 5) rect1.right = (rect.right << 5) - iSurfaceX; if(iSurfaceY + rect1.bottom > rect.bottom << 5) rect1.bottom = (rect.bottom << 5)- iSurfaceY; ShowBMPImage(x<0?dx:dx+(x<<5), y<0?dy:dy+(y<<5), rect1, pSourCell[pSurfaceData[number].nID].pBmpHeader, pS[SMap], SP[SMap], false); } } } } void CMap::DrawMapTran(int iStartX, int iStartY, RECT rect, long dx, long dy) { int x, y, i, j, number; int iSurfaceX, iSurfaceY; RECT rect1; if((dx < 0)||(dy < 0)) return; for(y = iStartY; y < rect.bottom-rect.top; y++) for(x = iStartX; x < rect.right-rect.left; x++) { number = (rect.top+y) * pHeader.nWidth + rect.left + x; if((pSurfaceData[number].nUseTranSition)&&(pSurfaceData[number].nID < 21)) { rect1.right = 96; rect1.bottom = 96; iSurfaceX = (x + rect.left) << 5; iSurfaceY = (y + rect.top) << 5; if((iSurfaceX - 32 < rect.right << 5)&&(iSurfaceX + 64 > rect.left << 5)&&(iSurfaceY - 32 < rect.bottom << 5)&&(iSurfaceY + 64 > rect.top << 5)) { if(x - 1 < 0) rect1.left = (1 - x)<<5; else rect1.left = 0; if(y - 1 < 0) rect1.top = (1 - y)<<5; else rect1.top = 0; if(x + 2 > rect.right - rect.left) rect1.right = (rect.right - rect.left - x + 1)<<5; else rect1.right = 96; if(y + 2 > rect.bottom - rect.top) rect1.bottom = (rect.bottom - rect.top - y + 1)<<5; else rect1.bottom = 96; TwoImageColorAnd(x-1>0?dx + ((x - 1)<<5):dx, y-1>0?dy + ((y - 1)<<5):dy, rect1, pS[SMap], (DWORD *)&pAlphaCell[1].pBmpHeader[1], SP[SMap], pAlphaCell[0].pBmpHeader->bfWidth<<1, false, 0); for(i = 0; i < 3; i++) for(j = 0; j < 3; j ++) { rect1.left = 0; rect1.top = 0; rect1.right = 32; rect1.bottom = 32; ShowBMPImage(i<<5, j<<5, rect1, pSourCell[pSurfaceData[number].nID].pBmpHeader, pS[SMapAlpha], SP[SMapAlpha], false); } rect1.left = 0; rect1.top = 0; rect1.right = 96; rect1.bottom = 96; TwoImageColorAnd(0, 0, rect1, pS[SMapAlpha], (DWORD *)&pAlphaCell[0].pBmpHeader[1], SP[SMapAlpha], pAlphaCell[1].pBmpHeader->bfWidth<<1, false, 0); if(x - 1 < 0) rect1.left = (1 - x)<<5; else rect1.left = 0; if(y - 1 < 0) rect1.top = (1 - y)<<5; else rect1.top = 0; if(x + 2 > rect.right - rect.left) rect1.right = (rect.right - rect.left - x + 1)<<5; else rect1.right = 96; if(y + 2 > rect.bottom - rect.top) rect1.bottom = (rect.bottom - rect.top - y + 1)<<5; else rect1.bottom = 96; TwoImageColorOr(x-1>0?dx + ((x - 1)<<5):dx, y-1>0?dy + ((y - 1)<<5):dy, rect1, pS[SMap], pS[SMapAlpha], SP[SMap], SP[SMapAlpha], false, 0); } } } } void CMap::MoveMapRD(RECT rect, long dx, long dy) { int iStartX, iStartY; RECT rect1; iStartX = SW[SMap] + ((rect.left - rMapRect.left)<<5); iStartY = SH[SMap] + ((rect.top - rMapRect.top)<<5); WORD *p=(WORD *)pS[SMap]+(((SH[SMap]-1)*SP[SMap])>>1)+(SW[SMap]-1); WORD *q=(WORD *)pS[SMap]+(((iStartY-1)*SP[SMap])>>1)+(iStartX-1); long asize=(iStartX>>5); long csize=iStartX-(asize << 5); long bsize=iStartY; if(((asize == 0 )&&(csize == 0))||(bsize == 0)) return; long lLine = SP[SMap]; __asm { ALIGN 8; mov esi,p; mov edi,q; mov ebx,bsize; //同时拷贝32个点 lineloop: mov eax,asize; mov edx,eax; push edi; push esi; cmp edx,0; jz remain; wholeloop: movq mm0,[edi]; movq mm1,[edi-8]; movq mm2,[edi-16]; movq mm3,[edi-24]; movq mm4,[edi-32]; movq mm5,[edi-40]; movq mm6,[edi-48]; movq mm7,[edi-56]; movq [esi],mm0; movq [esi-8],mm1; movq [esi-16],mm2; movq [esi-24],mm3; movq [esi-32],mm4; movq [esi-40],mm5; movq [esi-48],mm6; movq [esi-56],mm7; sub edi,64; sub esi,64; dec edx; jnz wholeloop; remain: mov eax,csize; mov ecx,eax; jecxz line; remainloop: mov ax,[edi]; //拷贝1个点 mov [esi],ax; sub edi,2; sub esi,2; dec ecx; jnz remainloop; line: pop esi; pop edi; mov eax,lLine sub esi,eax; sub edi,lLine; dec ebx; jnz lineloop; emms; } rect1.left = rect.left; rect1.right = rect.right; rect1.top = rect.top; rect1.bottom = rMapRect.top; iStartX = rect1.left - 10 > 0? -10: 0; iStartY = rect1.top - 10 > 0? -10: 0; DrawMapNoTran(iStartX, iStartY, rect1, dx, dy); //绘制无过渡图形 iStartX = rect1.left - 1 > 0? -1: 0; iStartY = rect1.top - 1 > 0? -1: 0; DrawMapTran(iStartX, iStartY, rect1, dx, dy); //绘制过渡图形 rect1.left = rect.left; rect1.right = rMapRect.left; rect1.top = rMapRect.top; rect1.bottom = rect.bottom; iStartX = rect1.left - 10 > 0? -10: 0; iStartY = rect1.top - 10 > 0? -10: 0; DrawMapNoTran(iStartX, iStartY, rect1, dx, dy); //绘制无过渡图形 iStartX = rect1.left - 1 > 0? -1: 0; iStartY = rect1.top - 1 > 0? -1: 0; DrawMapTran(iStartX, iStartY, rect1, dx, dy); //绘制过渡图形 } void CMap::MoveMapRU(RECT rect, long dx, long dy) { int iStartX, iStartY; RECT rect1; iStartX = SW[SMap] + ((rect.left - rMapRect.left)<<5); iStartY = rect.top - ((rMapRect.top)<<5); WORD *p=(WORD *)pS[SMap]+(SW[SMap]-1); WORD *q=(WORD *)pS[SMap]+iStartY*(SP[SMap]>>1)+(iStartX-1); long asize=(iStartX>>5); long csize=iStartX-(asize <<5); long bsize=SH[SMap]-iStartY; if(((asize == 0 )&&(csize == 0))||(bsize == 0)) return; long lLine = SP[SMap]; __asm { ALIGN 8; mov esi,p; mov edi,q; mov ebx,bsize; //同时拷贝32个点 lineloop: mov eax,asize; mov edx,eax; push edi; push esi; cmp edx,0; jz remain; wholeloop: movq mm0,[edi]; movq mm1,[edi-8]; movq mm2,[edi-16]; movq mm3,[edi-24]; movq mm4,[edi-32]; movq mm5,[edi-40]; movq mm6,[edi-48]; movq mm7,[edi-56]; movq [esi],mm0; movq [esi-8],mm1; movq [esi-16],mm2; movq [esi-24],mm3; movq [esi-32],mm4; movq [esi-40],mm5; movq [esi-48],mm6; movq [esi-56],mm7; sub edi,64; sub esi,64; dec edx; jnz wholeloop; remain: mov eax,csize; mov ecx,eax; jecxz line; remainloop: mov ax,[edi]; //拷贝1个点 mov [esi],ax; sub edi,2; sub esi,2; dec ecx; jnz remainloop; line: pop esi; pop edi; mov eax,lLine add esi,eax; add edi,lLine; dec ebx; jnz lineloop; emms; } rect1.left = rect.left; rect1.right = rMapRect.left; rect1.top = rect.top; rect1.bottom = rect.bottom; iStartX = rect1.left - 10 > 0? -10: 0; iStartY = rect1.top - 10 > 0? -10: 0; DrawMapNoTran(iStartX, iStartY, rect1, dx, dy); //绘制无过渡图形 iStartX = rect1.left - 1 > 0? -1: 0; iStartY = rect1.top - 1 > 0? -1: 0; DrawMapTran(iStartX, iStartY, rect1, dx, dy); //绘制过渡图形 rect1.left = rMapRect.left; rect1.right = rect.right; rect1.top = rMapRect.bottom; rect1.bottom = rect.bottom; iStartX = rect1.left - 10 > 0? -10: 0; iStartY = rect1.top - 10 > 0? -10: 0; DrawMapNoTran(iStartX, iStartY, rect1, dx, dy); //绘制无过渡图形 iStartX = rect1.left - 1 > 0? -1: 0; iStartY = rect1.top - 1 > 0? -1: 0; DrawMapTran(iStartX, iStartY, rect1, dx, dy); //绘制过渡图形 } void CMap::MoveMapLD(RECT rect, long dx, long dy) { int iStartX, iStartY; RECT rect1; iStartX = ((rect.left - rMapRect.left)<<5); iStartY = SH[SMap] + ((rect.top - rMapRect.top)<<5); WORD *p=(WORD *)pS[SMap]+(SH[SMap]-1)*(SP[SMap]>>1); WORD *q=(WORD *)pS[SMap]+(iStartY-1)*(SP[SMap]>>1)+iStartX; long asize=((SW[SMap]-iStartX)>>5); long csize=(SW[SMap]-iStartX)-(asize <<5); long bsize=iStartY; if(((asize == 0 )&&(csize == 0))||(bsize == 0)) return; long lLine = SP[SMap]; __asm { ALIGN 8; mov esi,p; mov edi,q; mov ebx,bsize; //同时拷贝32个点 lineloop: mov eax,asize; mov edx,eax; push edi; push esi; cmp edx,0; jz remain; wholeloop: movq mm0,[edi]; movq mm1,[edi+8]; movq mm2,[edi+16]; movq mm3,[edi+24]; movq mm4,[edi+32]; movq mm5,[edi+40]; movq mm6,[edi+48]; movq mm7,[edi+56]; movq [esi],mm0; movq [esi+8],mm1; movq [esi+16],mm2; movq [esi+24],mm3; movq [esi+32],mm4; movq [esi+40],mm5; movq [esi+48],mm6; movq [esi+56],mm7; add edi,64; add esi,64; dec edx; jnz wholeloop; remain: mov eax,csize; mov ecx,eax; jecxz line; remainloop: mov ax,[edi]; //拷贝1个点 mov [esi],ax; add edi,2; add esi,2; dec ecx; jnz remainloop; line: pop esi; pop edi; mov eax,lLine sub esi,eax; sub edi,lLine; dec ebx; jnz lineloop; emms; } rect1.left = rect.left; rect1.right = rect.right; rect1.top = rect.top; rect1.bottom = rMapRect.top; iStartX = rect1.left - 10 > 0? -10: 0; iStartY = rect1.top - 10 > 0? -10: 0; DrawMapNoTran(iStartX, iStartY, rect1, dx, dy); //绘制无过渡图形 iStartX = rect1.left - 1 > 0? -1: 0; iStartY = rect1.top - 1 > 0? -1: 0; DrawMapTran(iStartX, iStartY, rect1, dx, dy); //绘制过渡图形 rect1.left = rMapRect.right; rect1.right = rect.right; rect1.top = rMapRect.top; rect1.bottom = rect.bottom; iStartX = rect1.left - 10 > 0? -10: 0; iStartY = rect1.top - 10 > 0? -10: 0; DrawMapNoTran(iStartX, iStartY, rect1, dx, dy); //绘制无过渡图形 iStartX = rect1.left - 1 > 0? -1: 0; iStartY = rect1.top - 1 > 0? -1: 0; DrawMapTran(iStartX, iStartY, rect1, dx, dy); //绘制过渡图形 } void CMap::MoveMapLU(RECT rect, long dx, long dy) { int iStartX, iStartY; RECT rect1; iStartX = ((rect.left - rMapRect.left)<<5); iStartY = ((rect.top - rMapRect.top)<<5); WORD *p=(WORD *)pS[SMap]; WORD *q=(WORD *)pS[SMap]+iStartY*(SP[SMap]>>1)+iStartX; long asize=(SW[SMap]-iStartX)>>5; long csize=(SW[SMap]-iStartX)-(asize <<5); long bsize=(SH[SMap]-iStartY); if(((asize == 0 )&&(csize == 0))||(bsize == 0)) return; long lLine = SP[SMap]; __asm { ALIGN 8; mov esi,p; mov edi,q; mov ebx,bsize; //同时拷贝32个点 lineloop: mov eax,asize; mov edx,eax; push edi; push esi; cmp edx,0; jz remain; wholeloop: movq mm0,[edi]; movq mm1,[edi+8]; movq mm2,[edi+16]; movq mm3,[edi+24]; movq mm4,[edi+32]; movq mm5,[edi+40]; movq mm6,[edi+48]; movq mm7,[edi+56]; movq [esi],mm0; movq [esi+8],mm1; movq [esi+16],mm2; movq [esi+24],mm3; movq [esi+32],mm4; movq [esi+40],mm5; movq [esi+48],mm6; movq [esi+56],mm7; add edi,64; add esi,64; dec edx; jnz wholeloop; remain: mov eax,csize; mov ecx,eax; jecxz line; remainloop: mov ax,[edi]; //拷贝1个点 mov [esi],ax; add edi,2; add esi,2; dec ecx; jnz remainloop; line: pop esi; pop edi; mov eax,lLine add esi,eax; add edi,lLine; dec ebx; jnz lineloop; emms; } rect1.left = rMapRect.right; rect1.right = rect.right; rect1.top = rect.top; rect1.bottom = rect.bottom; iStartX = rect1.left - 10 > 0? -10: 0; iStartY = rect1.top - 10 > 0? -10: 0; DrawMapNoTran(iStartX, iStartY, rect1, dx, dy); //绘制无过渡图形 iStartX = rect1.left - 1 > 0? -1: 0; iStartY = rect1.top - 1 > 0? -1: 0; DrawMapTran(iStartX, iStartY, rect1, dx, dy); //绘制过渡图形 rect1.left = rect.left; rect1.right = rMapRect.right; rect1.top = rMapRect.bottom; rect1.bottom = rect.bottom; iStartX = rect1.left - 10 > 0? -10: 0; iStartY = rect1.top - 10 > 0? -10: 0; DrawMapNoTran(iStartX, iStartY, rect1, dx, dy); //绘制无过渡图形 iStartX = rect1.left - 1 > 0? -1: 0; iStartY = rect1.top - 1 > 0? -1: 0; DrawMapTran(iStartX, iStartY, rect1, dx, dy); //绘制过渡图形 } void CMap::DrawDynamicPic(RECT rect, long dx, long dy) { int iStartX, iStartY; int iSurfaceX, iSurfaceY; iStartX = 0; iStartY = rect.top - 4 > 0? -4: 0; int x, y, number; RECT rect1; DWORD dRight; for(y = iStartY; y < rect.bottom-rect.top; y++) for(x = iStartX; x < rect.right-rect.left; x++) { number = (rect.top+y) * pHeader.nWidth + rect.left + x; if((pSurfaceData[number].nID > 20)&&(pSurfaceData[number].nID != 255)) { rect1.right = 32; rect1.bottom = pSourCell[pSurfaceData[number].nID].pBmpHeader->bfHeight; iSurfaceX = (x + rect.left) << 5; iSurfaceY = (y + rect.top) << 5; if((iSurfaceX < rect.right << 5)&&(iSurfaceX + rect1.right > rect.left << 5)&&(iSurfaceY < rect.bottom << 5)&&(iSurfaceY + rect1.bottom > rect.top << 5)) { if(x < 0) rect1.left = (0 - x)<<5; else rect1.left = 0; if(y < 0) rect1.top = (0 - y)<<5; else rect1.top = 0; if(iSurfaceX + rect1.right > rect.right << 5) rect1.right = (rect.right << 5) - iSurfaceX; if(iSurfaceY + rect1.bottom > rect.bottom << 5) rect1.bottom = (rect.bottom << 5)- iSurfaceY; dRight = rect1.right; rect1.left += (iChangePic[pSurfaceData[number].nID - 21]<<5); rect1.right += (iChangePic[pSurfaceData[number].nID - 21]<<5); ShowBMPImage(x<0?dx:dx+(x<<5), y<0?dy:dy+(y<<5), rect1, pSourCell[pSurfaceData[number].nID].pBmpHeader, pS[SMap], SP[SMap], false); iStartX = x + rect.left - 1 > 0? -1 : 0; iStartY = y + rect.top - 1 > 0? -1 : 0; rect1.left = x > 0? x + rect.left : rect.left; rect1.top = y > 0? y + rect.top : rect.top; rect1.right = dRight >> 5; rect1.bottom = rect1.bottom >> 5; rect1.right = rect1.right+rect1.left+1 < rect.right ? rect1.right+rect1.left+1 : rect1.right+rect1.left; rect1.bottom = rect1.bottom+rect1.top+1 < rect.bottom ? rect1.bottom+rect1.top+1 : rect1.bottom+rect1.top; DrawMapTran(iStartX, iStartY, rect1, dx+(x<<5), dy+(y<<5)); //绘制过渡图形 } } } } void CMap::ChangeObjPosition(long x, long y, long dx, long dy, long realY) { _ObjLink* pLink = pObjLink; _ObjLink *pLink1, *pLink2; while(pLink != NULL) { if((pLink->dx == x)&&(pLink->dy == y)) { if((x == dx)&&(realY == (long)(pLink->ObjCell.nRealY))) { pLink->dy = dy; pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } break; } pLink1 = pLink; pLink = pLink->Next; } if(pLink == NULL) { pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } if(pLink == pObjLink) if(pLink->Next == NULL) { pLink->dx = dx; pLink->dy = dy; pLink->ObjCell.nRealY = realY; pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } else { pObjLink = pObjLink->Next; } else if(pLink->Next == NULL) pLink1->Next = NULL; else pLink1->Next = pLink->Next; pLink1 = pObjLink; pLink->dx = dx; pLink->dy = dy; pLink->ObjCell.nRealY = realY; while((pLink1 != NULL)&&((long)((pLink1->ObjCell.nRealY<<10) + pLink1->dx) < (long)((realY<<10) + dx))) { pLink2 = pLink1; pLink1 = pLink1->Next; } if(pLink1 == pObjLink) { pLink->Next = pObjLink; pObjLink = pLink; pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } else if(pLink1 == NULL) { pLink2->Next = pLink; pLink->Next = NULL; pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } else { pLink2->Next = pLink; pLink->Next = pLink1; pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } void CMap::ChangeObjID(long x, long y, int type, int id, long realY) { _ObjLink* pLink = pObjLink; _ObjLink *pLink1, *pLink2; while(pLink != NULL) { if((pLink->dx == x)&&(pLink->dy == y)) { if(realY == (long)pLink->ObjCell.nRealY) { pLink->ObjCell.nType = type; pLink->ObjCell.nID = id; pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } break; } pLink1 = pLink; pLink = pLink->Next; } if(pLink == NULL) { pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } if(pLink == pObjLink) if(pLink->Next == NULL) { pLink->ObjCell.nType = type; pLink->ObjCell.nID = id; pLink->ObjCell.nRealY = realY; pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } else { pObjLink = pObjLink->Next; } else if(pLink->Next == NULL) pLink1->Next = NULL; else pLink1->Next = pLink->Next; pLink1 = pObjLink; pLink->ObjCell.nType = type; pLink->ObjCell.nID = id; pLink->ObjCell.nRealY = realY; while((pLink1 != NULL)&&((long)((pLink1->ObjCell.nRealY<<10) + pLink1->dx) < (long)((realY<<10) + pLink->dx))) { pLink2 = pLink1; pLink1 = pLink1->Next; } if(pLink1 == pObjLink) { pLink->Next = pObjLink; pObjLink = pLink; pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } else if(pLink1 == NULL) { pLink2->Next = pLink; pLink->Next = NULL; pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } else { pLink2->Next = pLink; pLink->Next = pLink1; pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; } pLink = NULL; pLink1 = NULL; pLink2 = NULL; return; }